#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QtGui>
#include "ui_mainwindow.h"
#include <windows.h>
#include "Common/common.h"
#include "Thread/camerathread.h"
#include "Thread/cameraworker.h"
#include "Thread/algthread.h"
#include "Thread/saveimgthread.h"

#include "algdialog.h"

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    MainWindow(QWidget* parent = 0);
    ~MainWindow();

    void InitTable();
    QString GetRunTime();
    void OpenHalconWindows();
    void closeEvent(QCloseEvent*);
    int status;

    QList<SaveImgThread*> m_tLSaveImg;
    SaveImgThread* m_tSaveImg1;
    SaveImgThread* m_tSaveImg2;
    SaveImgThread* m_tSaveImg3;


    void upTabView(QList<int> qlCount,QList<int> qlCD1,QList<int> qlCD2,QList<int> qlCD3);

    void clearAllData();
protected:
    void changeEvent(QEvent* e);

private:
    Ui::MainWindow* ui;
    int init_SDK();

    int  GUI_init_parameter(int hCamera, tSdkCameraCapbility* pCameraInfo,int index);
    int  GUI_init_Resolution(int hCamera, tSdkCameraCapbility* pCameraInfo);
    int  GUI_set_Resolution(int hCamera, tSdkCameraCapbility* pCameraInfo,int index);
    int  GUI_init_exposure(int hCamera, tSdkCameraCapbility* pCameraInfo);
    int  GUI_init_isp(int hCamera, tSdkCameraCapbility* pCameraInfo);
    int  GUI_init_Trigger(int hCamera, tSdkCameraCapbility* pCameraInfo);

    void CreateCameraSaveFile();

public slots:
    void sloAlgInfo(int nIndx);
    void onTimerOut();
    void appQuit();
private slots:


    void CameraResult(int nResult);
    void camera_statues();





    void on_Bt_implement_clicked();

    void on_tabWidget_currentChanged(int index);

    void on_checkBox_NG_clicked(bool checked);

    void on_checkBox_OK_clicked(bool checked);

    void on_checkBox_BJ_clicked(bool checked);

    void on_pushButton_4_clicked();

private:

    void OpenFileImg(int index);
    void CarouselImage(int index);

    void RdConfig();

    HalconCpp::HObject m_hImage;
    HalconCpp::HTuple m_hvHandle;
    // 文件信息
    // 图片切换
    QString m_vFilePath[8];
    QStringList m_vFileList[8];
    int m_vFileIndex[8];

    QTimer* m_timer;
    QLabel* m_camera_statuesFps;
    bool   exposure_time_lineedit_status;

public:

    int m_nOpenHalcon = 0;

    HalconCpp::HTuple m_hvMainHandle1;
    HalconCpp::HTuple m_hvMainHandle2;
    HalconCpp::HTuple m_hvMainHandle3;
    HalconCpp::HTuple m_hvMainHandle4;
    HalconCpp::HTuple c1_hvCCDHandle;
    HalconCpp::HTuple c2_hvCCDHandle;
    HalconCpp::HTuple c3_hvCCDHandle;
    HalconCpp::HTuple c4_hvCCDHandle;

    int nCurrent = 0;
    QList<CameraInfo> lCamers;
    CameraInfo currentCamer;
    CameraThread* currentTcm;
    CameraThread* m_tCamera1;
    CameraThread* m_tCamera2;
    CameraThread* m_tCamera3;


    QList<AlgThread*> m_tLAlg;
    AlgThread* m_tAlg1;
    AlgThread* m_tAlg2;
    AlgThread* m_tAlg3;

    AlgDialog* m_algDlg;


    int m_parm[10];

    int m_nImplement = 0;
    M_R_IMPURITY m_impurity;

    /* Timer */
    QTimer *m_pTimer;
    int m_nIndex;

    int m_nMesc;
    int m_nMinute;
    int m_nHour;

    /* 统计 */
    QList<int> qlCount;
    QList<int> qlCD1;
    QList<int> qlCD2;
    QList<int> qlCD3;



    int m_nSum = 0;
    int m_nNG = 0;
    int m_nOK = 0;
};

#endif // MAINWINDOW_H
